1   /*
2    * Copyright (c) 2004-2005, University Health Network.  All rights reserved. Distributed under the BSD 
3    * license (see http://opensource.org/licenses/bsd-license.php).
4    *  
5    * Created on 5-Jan-2005
6    */
7   package ca.uhn.cache.internal.impl;
8   
9   import java.util.Date;
10  import java.util.HashMap;
11  import java.util.Map;
12  
13  import ca.uhn.cache.CacheReasonEnum;
14  import ca.uhn.cache.VolatilityEnum;
15  import ca.uhn.cache.impl.Chunk;
16  import ca.uhn.cache.impl.Query;
17  import ca.uhn.cache.internal.IChunk;
18  import ca.uhn.cache.internal.IUnusedChunkRule;
19  import junit.framework.TestCase;
20  
21  /***
22   * Test cases for DefaultUnusedChunkRule. 
23   *  
24   * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
25   * @version $Revision: 1.1 $ updated on $Date: 2005/01/24 22:52:10 $ by $Author: bryan_tripp $
26   */
27  public class DefaultUnusedChunkRuleTest extends TestCase {
28  
29      /***
30       * @param theName ...
31       */
32      public DefaultUnusedChunkRuleTest(String theName) {
33          super(theName);
34      }
35      
36      /***
37       */
38      public void testGetVoguenessModifier() {
39          Map modifiers = new HashMap();
40          modifiers.put(CacheReasonEnum.PRE_FETCH, new Long(10 * 60 * 1000));
41          modifiers.put(CacheReasonEnum.QUERY, new Long(5 * 60 * 1000));        
42          IUnusedChunkRule rule = new DefaultUnusedChunkRule(modifiers);
43          
44          IChunk c1 = getChunk(new CacheReasonEnum[0]);
45          assertEquals(0, rule.getVoguenessModifier(c1));
46          
47          IChunk c2 = getChunk(new CacheReasonEnum[] {CacheReasonEnum.PRE_FETCH});
48          assertEquals(10 * 60 * 1000, rule.getVoguenessModifier(c2));
49          
50          IChunk c3 = getChunk(new CacheReasonEnum[] {CacheReasonEnum.QUERY});
51          assertEquals(5 * 60 * 1000, rule.getVoguenessModifier(c3));
52          
53          IChunk c4 = getChunk(new CacheReasonEnum[] {CacheReasonEnum.PRE_FETCH, CacheReasonEnum.QUERY});
54          assertEquals(15 * 60 * 1000, rule.getVoguenessModifier(c4));
55      }
56      
57      private IChunk getChunk(CacheReasonEnum[] theReasons) {
58          Date now = new Date();
59          return new Chunk("", VolatilityEnum.STABLE, now, now, now, theReasons, new Query());
60      }
61  
62  }